package org.infodavid.common.notifier.impl;

import org.joda.time.DateTime;

import org.infodavid.common.notifier.IAcknowledgment;
import org.infodavid.common.notifier.INotifierCommand;

/**
 * The Class AcknowledgmentImpl.
 */
public class AcknowledgmentImpl implements IAcknowledgment {

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = -5399118682809718087L;

  /** The content. */
  private final String content;

  /** The date. */
  private final DateTime date;

  /** The error. */
  private final Throwable error;

  /** The source command. */
  private final INotifierCommand source;

  /** The retry count. */
  private int retryCount = 0;

  /**
   * Instantiates a new acknowledgment impl.
   * @param cmd the command
   */
  public AcknowledgmentImpl(final INotifierCommand cmd) {
    source = cmd;
    content = null;
    date = new DateTime();
    error = null;
  }

  /**
   * Instantiates a new acknowledgment impl.
   * @param cmd the command
   * @param arg0 the arg0
   */
  public AcknowledgmentImpl(final INotifierCommand cmd, final Throwable arg0) {
    source = cmd;
    content = null;
    date = new DateTime();
    error = arg0;
  }

  /**
   * Instantiates a new acknowledgment impl.
   * @param cmd the command
   * @param arg0 the arg0
   * @param arg1 the arg1
   */
  public AcknowledgmentImpl(final INotifierCommand cmd, final DateTime arg0, final Throwable arg1) {
    source = cmd;
    content = null;
    date = arg0;
    error = arg1;
  }

  /**
   * Instantiates a new acknowledgment impl.
   * @param cmd the command
   * @param arg0 the arg0
   * @param arg1 the arg1
   * @param arg2 the arg2
   */
  public AcknowledgmentImpl(final INotifierCommand cmd, final String arg0, final DateTime arg1,
      final Throwable arg2) {
    source = cmd;
    content = arg0;
    date = arg1;
    error = arg2;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#getSource()
   */
  public INotifierCommand getSource() {
    return source;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#getRetryCount()
   */
  public int getRetryCount() {
    return retryCount;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#setRetryCount(int)
   */
  public void setRetryCount(final int value) {
    retryCount = value;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#getContent()
   */
  public String getContent() {
    return content;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#getDate()
   */
  public DateTime getDate() {
    return date;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see org.infodavid.common.notifier.IAcknowledgment#getError()
   */
  public Throwable getError() {
    return error;
  }

  /**
   * See super class or interface. (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  public String toString() {
    final StringBuilder builder = new StringBuilder();

    builder.append(super.toString());
    builder.append("AcknowledgmentImpl [content=");
    builder.append(content);
    builder.append(", date=");
    builder.append(date);
    builder.append(", error=");
    builder.append(error);
    builder.append(", retryCount=");
    builder.append(retryCount);
    builder.append(", source=");
    builder.append(source);
    builder.append("]");

    return builder.toString();
  }
}
